package io.xxx.xbutler.core.select.receiver;

import io.xxx.xbutler.data.ContactMapper;
import io.xxx.xbutler.data.RoomMapper;
import io.xxx.xbutler.domain.Contact;
import io.xxx.xbutler.domain.Room;
import io.xxx.xbutler.domain.task.Receiver;
import io.xxx.xbutler.domain.task.ReceiverType;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public abstract class AbstractReceiverSelector implements ReceiverSelector {

    @Resource
    protected ContactMapper contactMapper;

    @Resource
    protected RoomMapper roomMapper;

    protected Receiver buildReceiver(Contact contact) {
        return buildReceiver(
                ReceiverType.CONTACT,
                contact.getId(),
                contact.getSerialNo(),
                contact.getName(),
                contact.getStoreId(),
                contact.getStoreCode(),
                contact.getStoreName()
        );
    }

    protected Receiver buildReceiver(Room room) {
        return buildReceiver(
                ReceiverType.ROOM,
                room.getId(),
                room.getSerialNo(),
                room.getName(),
                room.getStoreId(),
                room.getStoreCode(),
                room.getStoreName()
        );
    }

    private Receiver buildReceiver(ReceiverType receiverType,
                                   String receiverId,
                                   String receiverSerialNo,
                                   String receiverName,
                                   Long storeId,
                                   String storeCode,
                                   String storeName) {
        return new Receiver()
                .setType(receiverType)
                .setId(receiverId)
                .setSerialNo(receiverSerialNo)
                .setName(receiverName)
                .setStoreId(storeId)
                .setStoreCode(storeCode)
                .setStoreName(storeName);
    }
}
